﻿<%@ Page Title="" Language="C#" MasterPageFile="~/W_View/PageMaster.Master" AutoEventWireup="true" CodeBehind="S_Inspeaccse_Page.aspx.cs" Inherits="STHPMS1.Web.W_View.Survey.S_Inspeaccse_Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <%= UiHelper.RefJsFileHtml("/Scripts/Control/datagrid.js")%>
    <%= UiHelper.RefJsFileHtml("/Scripts/Jquery/ajaxfileupload.js")%>
    <script type="text/javascript">
        function closeFile()
        {
            $("#linkUpload").text("上传");
            $('#dlgImport').dialog('close');
            $("#fileHid").val('');//清空隐藏域
        }
        //上传
        function ajaxFileUpload() {
            $.ajaxFileUpload
            (
                {
                    url: '/api/S_Inspeaccse/uploadFile', //用于文件上传的服务器端请求地址
                    secureuri: false, //是否需要安全协议，一般设置为false
                    fileElementId: 'file1', //文件上传域的ID
                    dataType: 'string', //返回值类型 一般设置为json

                    success: function (data)  //服务器成功响应处理函数
                    {
                        var file = data;
                        //写入隐藏域
                        $("#fileHid").val(file);
                        $("#linkUpload").text("上传成功");
                        //alert($("#fileHid").val())
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                        
                    }
                }
            )
            return false;
        }
        //上传文件验证
        function upLoad() {
            if ($("#linkUpload").text() == "上传") {
                var file = $("#file1").val();//上传文件
                if (file == "") {
                    alert("请选择上传数据");
                    return;
                }
                else {
                    var extStart = file.lastIndexOf(".");
                    var ext = file.substring(extStart, file.length).toUpperCase();
                    if (ext != ".XLS" && ext != ".XLSX") {
                        alert("请上传有效Excel文件");
                        return;
                    }
                }
                ajaxFileUpload();
            }
        }
        //导入处理
        function saveFile() {
            var rdId = $("#cmbRoadway2").combobox("getValue");//路线编号
            var dir = $("#cmbDirection").combobox("getValue");//调查方向
           
            var file = $("#fileHid").val();//上传后的Excel路径
            if (file == "")
            {
                alert("请上传数据文件");
                return;
            }
            var v = $("#id_type").val();//评定ID和导入类型
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/S_Inspeaccse/saveFile?file=" + encodeURI(file) + "&rdid=" + rdId + "&dir=" + encodeURI(dir) + "&v=" + encodeURI(v),
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    $("#fileHid").val('');//清空隐藏域
                    $('#dlgImport').dialog('close');
                    search(null, null);
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                    closeFile();
                }
            });
        }
        //保存评定信息
        function save() {
            var rdName = $("#cmbRoadway").combobox("getText")
            var y = $("#cmbY").combobox("getText")
            var m = $("#cmbM").combobox("getText")
            if (m == "请选择") {
                m = "";
            }
            else {
                m = "_" + m;
            }
            var inspecid = rdName +"_"+ y + m;
            $.ajax({
                url: "/api/S_Inspeaccse?inspecid=" + encodeURI(inspecid) + "&rdid=" + encodeURI($("#cmbRoadway").combobox("getValue")) + "&y=" + y,
                type: "post",
                success: function (msg) {
                    $('#dlg').dialog('close');
                    search(null, null);
                },

                error: function (msg) {
                    //错误处理
                    alert(msg.responseText);
                }
            });
        }
        function add(flag) {

            var title = "新增评定数据";

            $('#dlg').dialog('open');
        }

        function del() {
            var row = $('#dg').datagrid('getSelected');
            if (!row) {
                $.messager.alert('消息提示', '删除数据时，请选择一项!', 'warning');
                return;
            }

            deleteData($('#dg'), $('#dlg'), "/api/S_Inspeaccse");
        }



        function search(n, o) {

            var url = '/api/S_Inspeaccse';

            $('#dg').datagrid({ url: url, pageNumber: 1 });
        }


        $(function () {
            var number = '<%= Page.RouteData.Values["page"] %>';
            var size = '<%= Page.RouteData.Values["size"] %>';

            dataGridBind($('#dg'), '/api/S_Inspeaccse', '评定数据列表显示', $('#tb'), number, size);

            $('.validatebox-text').bind('blur', function () {
                $(this).validatebox('enableValidation').validatebox('validate');
            });

        })
    </script>

    <script>
        function showBySite() {
            var htmlstr = '<div style="width:50px; height:5px; border:1px solid red;"/>';
          
            var options = {
                title: "操作提示",
                msg: htmlstr,
                showType: 'slide',
                timeout: 800
            };
            $.messager.show(options);
        }
        //路基
        function lj(val, row) {
            //if (val == false) {
            //    var v = row.Inspecid + "|lj";
            //    return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            //}
            //return "√";
            return "<a href='#' onclick='showBySite();'>点我</a>"
        }
        //设施
        function ss(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|ss";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //构造物
        function gzw(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|gzw";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //车辙
        function cz(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|cz";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //强度
        function qd(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|qd";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
       
        //抗滑
        function kh(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|kh";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //平整度
        function pzd(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|pzd";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //沥青病害
        function lq(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|lq";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //砂石病害
        function shas(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|shas";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //水泥病害
        function sn(val, row) {
            if (val == false) {
                var v = row.Inspecid + "|sn";
                return "<a href='#' v='" + v + "' onclick='impt(this);'>导入</a>"
            }
            return "√";
        }
        //评定
        function pd(val, row) {
            if (val == false) {
               
                return "未评定"
            }
            return "已评定";
        }

        function pdAccess(val,row)
        {
            return "<a href='#' v='" + row.Inspecid + "' onclick='access(this)'>生成</a>"
        }

        function access(obj)
        {
            var inspecid = $(obj).attr("v");
            $.messager.progress({
                title: '请等待',
                msg: '正在处理中...'
            });
            $.ajax({
                url: "/api/S_Inspeaccse/Access?inspecid=" + encodeURI(inspecid),
                type: "post",
                complete: function () {
                    $.messager.progress('close');
                },
                success: function (msg) {
                    $('#dlg').dialog('close');
                    search(null, null);
                },

                error: function (msg) {
                    //错误处理
                    $.messager.alert('错误提示', msg.responseText, "error");
                }
            });
        }

        //导入的点击事件
        function impt(id_type) {
            $("#linkUpload").text("上传");
            $("#fileHid").val('');//清空隐藏域
            $("#id_type").val($(id_type).attr("v"));//保存评定ID和导入类型
            $('#dlgImport').dialog('open');
        }

       
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="p" class="easyui-progressbar" style="width:100px;" value="20" text="20%"></div>
    <table id="dg" class="easyui-datagrid content-place" ajaxcached="false">
        <thead>
            <tr>
                <th data-options="field:'Inspecid',width:180">评定ID</th>
                <th data-options="field:'Issub',width:120" formatter='lj'>路基数据导入</th>
                <th data-options="field:'Isrddf',width:120" formatter='ss'>沿线设施数据导入</th>
                <th data-options="field:'Isbtstrut',width:120" formatter='gzw'>桥隧构造物数据导入</th>
                <th data-options="field:'Isrutting',width:120" formatter='cz'>车辙数据导入</th>
                <th data-options="field:'Isrdpssi',width:120" formatter='qd'>结构强度数据导入</th>
                <th data-options="field:'Isasphalt',width:140" formatter='lq'>病害数据导入(沥青路面)</th>
                <th data-options="field:'Isgravel',width:140" formatter='shas'>病害数据导入(砂石路面)</th>
                <th data-options="field:'Iscement',width:140" formatter='sn'>病害数据导入(水泥路面)</th>
                <th data-options="field:'Isrdfrc',width:120" formatter='kh'>抗滑数据导入</th>
                <th data-options="field:'Isrdrgh',width:120" formatter='pzd'>平整度数据导入</th>
                <th data-options="field:'Isaccess',width:80" formatter='pd'>评定状态</th>
                <th data-options="field:'null',width:80" formatter='pdAccess'>操作</th>
            </tr>
        </thead>
    </table>

    <!--测试数据命令-->
    <div id="tb">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add(-1)">添加</a>
 
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="del()">删除</a>

        <a  href="/down" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" >模板下载</a>
    </div>

    <!--测试详细页面-->
    <div id="dlg" class="easyui-dialog" title="生成评定ID" style="width: 320px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttons'
			">
        <form id="fm">
            <table>
                <tr>
                    <td>路线名称:</td>
                    <td>
                        <select id="cmbRoadway" class="easyui-combobox" panelheight="80" style="width: 100px"
                            data-options="url:'/api/S_Inspeaccse/RoadWay',method:'get',valueField:'Rdwayid',textField:'Name',
                            onLoadSuccess:function(data){ $('#cmbRoadway').combobox('setValue',data[0].Rdwayid);}">
                        </select></td>
                </tr>
                <tr>
                    <td>调查年份:</td>
                    <td>
                        <select id="cmbY" class="easyui-combobox" panelheight="80" style="width: 100px">
                            <option selected="selected">2015</option>
                            <%for (int i = 2013; i < 2025; i++)
                              { %>
                            <option><%=i%></option>
                            <%} %>
                        </select></td>
                </tr>
                <tr>
                    <td>调查月份:</td>
                    <td>
                        <select id="cmbM" class="easyui-combobox" panelheight="80" style="width: 100px">
                            <option selected="selected">请选择</option>
                            
                            <option>01</option>
                            <option>02</option>
                            <option>03</option>
                            <option>04</option>
                            <option>05</option>
                            <option>06</option>
                            <option>07</option>
                            <option>08</option>
                            <option>09</option>
                            <option>10</option>
                            <option>11</option>
                            <option>12</option>
                        </select></td>
                </tr>
            </table>
        </form>
    </div>

    <!--编辑数据命令-->
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:save()">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#dlg').dialog('close')">取消</a>

    </div>

    <!--导入数据-->
    <div id="dlgImport" class="easyui-dialog" title="导入数据" style="width: 320px; height: 250px; padding: 10px" closed="true" data-options="
				iconCls: 'icon-save',
				buttons: '#dlg-buttonsImport'
			">
       
            <table>
                <tr>
                    <td>路线名称:</td>
                    <td>
                        <select id="cmbRoadway2" class="easyui-combobox" panelheight="80" style="width: 100px"
                            data-options="url:'/api/S_Inspeaccse/RoadWay',method:'get',valueField:'Rdwayid',textField:'Name',
                            onLoadSuccess:function(data){ $('#cmbRoadway2').combobox('setValue',data[0].Rdwayid);}">
                        </select></td>
                </tr>
                <tr>
                    <td>调查方向</td>
                    <td>
                        <select id="cmbDirection" class="easyui-combobox" panelheight="80" style="width: 100px"
                            data-options="url:'/api/data/direction',method:'get',valueField:'id',textField:'text',
                              onLoadSuccess:function(data){ $('#cmbDirection').combobox('setValue',data[0].id);}">
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>导入源:</td>
                    <td>
                        <input id="id_type" type="hidden" />
                        <input id="fileHid" type="hidden" />
                        <input type="file" id="file1" name="file" style="width: 150px"/>
                        <a href="javascript:void(0)" id="linkUpload"  onclick="javascript:upLoad();">上传</a>
                    </td>
                </tr>
            </table>
      
    </div>
    <!--导入数据命令-->
    <div id="dlg-buttonsImport">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:saveFile();">确定</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:closeFile()">取消</a>
    </div>
</asp:Content>
